package com.iukcy;

import com.sun.jdmk.comm.HtmlAdaptorServer;

import javax.management.*;

/**
 * @description: TODO
 * @author zhangzhufu
 * @date 2020/9/27 9:49
 * @version 1.0
 */
public class HelloAgent implements NotificationListener {
    private MBeanServer mbs;

    public HelloAgent() {
        this.mbs = MBeanServerFactory.createMBeanServer("HelloAgent");

        Hello hw = new Hello();
        ObjectName helloWorldName = null;
        try{
            //这里必须与MBean对象名称相同
            helloWorldName = new ObjectName("HelloAgent:name=hello");
            mbs.registerMBean(hw, helloWorldName);
        } catch (Exception e) {
            e.printStackTrace();
        }
        startHtmlAdaptorServer();
    }

    public void startHtmlAdaptorServer(){
        HtmlAdaptorServer htmlAdaptorServer = new HtmlAdaptorServer();
        ObjectName adapterName = null;
        try {
            // 多个属性使用,分隔
            adapterName = new ObjectName("HelloAgent:name=htmladapter,port=9092");
            htmlAdaptorServer.setPort(9092);
            mbs.registerMBean(htmlAdaptorServer, adapterName);
            htmlAdaptorServer.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    @Override
    public void handleNotification(Notification notification, Object handback) {

    }
    public static void main(String args[]){
        System.out.println(" hello agent is running");
        HelloAgent agent = new HelloAgent();
    }


}